package 通用路径写法.Test01;

import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.IOException;

//通用获取路劲方法
public class Test01 {
    public static void main(String[] args) {
        FileInputStream fis = null;

        String path = Thread.currentThread().getContextClassLoader().getResource("IO流/myFile2").getPath();

        System.out.println(path);//路径有中文乱码了，会出错，直接返回流就不会    详test02
        try {
            fis = new FileInputStream(path);
            byte[] bytes = new byte[fis.available()];
            fis.read(bytes);
            System.out.println(new String(bytes));

        } catch (FileNotFoundException e) {
            e.printStackTrace();
        } catch (IOException e) {
            e.printStackTrace();
        } finally {
            try {
                fis.close();
            } catch (IOException e) {
                e.printStackTrace();
            }
        }
    }
}
